/*
 * Copyright (C) 2018 xuexiangjys(xuexiangjys@163.com)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.wakala.employment.http;

import static com.xuexiang.xhttp2.annotation.NetMethod.FORM_BODY;
import static com.xuexiang.xhttp2.annotation.NetMethod.GET;
import static com.xuexiang.xhttp2.annotation.NetMethod.POST;
import static com.xuexiang.xhttp2.annotation.NetMethod.JSON_OBJECT;
import static com.xuexiang.xhttp2.annotation.NetMethod.PUT;
import static com.xuexiang.xhttp2.annotation.NetMethod.URL_GET;

import com.wakala.employment.adapter.bean.JobInfoPage;
import com.wakala.employment.adapter.bean.JobInfoSearchRequest;
import com.wakala.employment.adapter.entity.JobInfoVo;
import com.wakala.employment.adapter.entity.LoginInfo;
import com.wakala.employment.adapter.entity.User;
import com.wakala.employment.adapter.jobCategory.JobCategoryAttrTreeVo;
import com.wakala.employment.adapter.jobCategory.JobCategoryTreeVo;
import com.wakala.employment.http.bean.ArticlePage;
import com.wakala.employment.http.bean.ArticleVo;
import com.wakala.employment.http.bean.CategoryMenuVo;
import com.wakala.employment.http.bean.CollectionPage;
import com.wakala.employment.http.bean.DeviceTokenBo;
import com.wakala.employment.http.bean.FeedbackPage;
import com.wakala.employment.http.bean.FeedbackRequest;
import com.wakala.employment.http.bean.FilterConditionVo;
import com.wakala.employment.http.bean.JobBookingBo;
import com.wakala.employment.http.bean.JobBookingVo;
import com.wakala.employment.http.bean.JobCategoryVo;
import com.wakala.employment.http.bean.JobInfoRequest;
import com.wakala.employment.http.bean.ResumeInfoPage;
import com.wakala.employment.http.bean.ResumeInfoRequest;
import com.wakala.employment.http.bean.ResumeInfoSearchRequest;
import com.wakala.employment.http.bean.ResumeInfoVo;
import com.wakala.employment.http.bean.ResumeJobCategoryAttrResultRequest;
import com.wakala.employment.http.bean.ResumeJobCategoryRequest;
import com.wakala.employment.http.bean.SystemCityTreeVo;
import com.wakala.employment.http.bean.UpdateInfoVo;
import com.wakala.employment.http.bean.UserAddressPage;
import com.wakala.employment.http.bean.UserCommunicateRecordPage;
import com.wakala.employment.http.bean.UserCommunicateRecordRequest;
import com.wakala.employment.http.bean.UserEditRequest;
import com.xuexiang.xhttp2.annotation.NetMethod;
import com.xuexiang.xhttp2.annotation.RequestParams;
import com.xuexiang.xhttp2.cache.model.CacheMode;
import com.xuexiang.xhttp2.model.ApiResult;
import com.xuexiang.xhttp2.model.XHttpRequest;

import java.util.List;

import io.reactivex.Observable;
import okhttp3.RequestBody;
import retrofit2.http.Body;
import retrofit2.http.GET;
import retrofit2.http.Headers;
import retrofit2.http.POST;
import retrofit2.http.Path;

/**
 * 测试api协议
 *
 * @author xuexiang
 * @since 2018/7/16 下午6:48
 */
public class TestApi {

    @RequestParams(url = "/user/addUser", accessToken = false)
    public static class UserService_AddUser extends XHttpRequest {

        /**
         *
         */
        public User request;

        @Override
        protected Boolean getResponseEntityType() {
            return null;
        }
    }

    @RequestParams(url = "/user/findUsers", accessToken = false)
    public static class UserService_findUsers extends XHttpRequest {
        /**
         * 第几页数
         */
        public int pageNum;
        /**
         * 每页的数量
         */
        public int pageSize;

        @Override
        protected List<User> getResponseEntityType() {
            return null;
        }
    }


    /**
     * 订单
     */
    public interface IOrder {
        /**
         * 购买书
         *
         * @param bookId 图书ID
         * @param userId 用户ID
         * @param number 购买数量
         */
        @NetMethod(parameterNames = {"bookId", "userId", "number"}, url = "/order/addOrder/", accessToken = false)
        Observable<Boolean> buyBook(int bookId, int userId, int number);
    }

    /**
     * 不限制--公共接口
     */
    public interface IUniversal {
        /**
         * 提交反馈意见
         *
         */
        @NetMethod(action = POST, paramType = JSON_OBJECT, url = "/api/front/feedback/save", cacheMode = CacheMode.FIRST_CACHE, cacheTime = 120, accessToken = true)
        Observable<Void> postFeedback(FeedbackRequest request);

    }


    /**
     * 身份验证
     */
    public interface IAuthorization {
        @NetMethod(parameterNames = { "phone" },paramType = FORM_BODY, url = "/api/front/sendCode", accessToken = false)
        Observable<Object> sendCode(String phone);

        /**
         * 手机验证码登录获取token
         *
         * @param phone 用户名
         * @param captcha  密码
         */
        @NetMethod(parameterNames = {"phone", "captcha"}, url = "/api/front/login/mobile", accessToken = false)
        Observable<LoginInfo> loginMobile(String phone, String captcha);

        /**
         * 退出登录
         * @return
         */
        @NetMethod(parameterNames = {}, action = GET ,url = "/api/front/logout", accessToken = true)
        Observable<String> loginOut();

        /**
         * 登录获取token
         *
         * @param account 手机号码
         * @param password  密码
         */
        @NetMethod(parameterNames = {"account", "password"}, url = "/api/front/login/pwd", accessToken = false)
        Observable<LoginInfo> login(String account, String password);

    }


    /**
     * 使用的是retrofit的接口定义
     */
    public interface LoginService {
        @POST("/authorization/login/")
        @Headers({"Content-Type: application/json", "Accept: application/json"})
        Observable<ApiResult<LoginInfo>> login(@Body RequestBody jsonBody);


        @POST("/authorization/login/")
        @Headers({"Content-Type: application/json", "Accept: application/json"})
        Observable<ApiResult<LoginInfo>> login(@Body User user);
    }


    /**
     * 使用的是retrofit的接口定义
     */
    public interface IUserService {

        /**
         * 获取登录用户信息
         * @return
         */
        @NetMethod(parameterNames = {}, action = GET ,url = "/api/front/user", cacheMode = CacheMode.NO_CACHE,accessToken = true)
        @Headers({"Content-Type: application/json", "Accept: application/json"})
        Observable<User> getLoginUserInfo();

        /*@NetMethod( action = POST ,url = "/api/front/app/updateDeviceToken", cacheMode = CacheMode.NO_CACHE,accessToken = true)
        @Headers({"Content-Type: application/json", "Accept: application/json"})
        Observable<Object> updateDeviceToken(@Body DeviceTokenBo deviceTokenBo);*/

        @NetMethod(url = "/api/front/app/updateDeviceToken",action = POST, paramType = JSON_OBJECT, cacheMode = CacheMode.DEFAULT, accessToken = true)
        Observable<Object> updateDeviceToken(DeviceTokenBo bo);

        @POST("/user/registerUser/")
        @Headers({"Content-Type: application/json", "Accept: application/json"})
        Observable<ApiResult<Boolean>> registerUser(@Body RequestBody jsonBody);


        @POST("/user/registerUser/")
        @Headers({"Content-Type: application/json", "Accept: application/json"})
        Observable<ApiResult> register(@Body User user);

        /**
         * 修改用户信息
         * @return
         */
        @NetMethod(url = "/api/front/user/edit", paramType = JSON_OBJECT ,cacheMode = CacheMode.NO_CACHE,accessToken = true)
        Observable<Object> userEdit(UserEditRequest userEditRequest);

        /**
         * 用户地址列表
         * @return
         */
        @NetMethod(url = "/api/front/address/list",action = GET,  cacheMode = CacheMode.NO_CACHE, accessToken = true)
        Observable<UserAddressPage> userAddressList();

        /**
         * 用户沟通记录
         * @param request
         * @return
         */
        @NetMethod(url = "/api/front/communicate/list",paramType = JSON_OBJECT, cacheMode = CacheMode.NO_CACHE, accessToken = true)
        Observable<UserCommunicateRecordPage> userCommunicateRecordList(@Body UserCommunicateRecordRequest request);
    }

    public interface IJobCategoryService{
        /**
         * 获取tree结构的列表
         *
         */
        @NetMethod(url = "/api/front/jobCategory/list/tree/all", action = GET, accessToken = true)
        Observable<List<JobCategoryTreeVo>> listJobCategoryTreeAll();

        /**
         * 获取tree结构的列表
         *
         */
        @NetMethod(url = "api/front/jobCategory/attr/list/tree", parameterNames = {"categoryId"},action = GET, accessToken = true)
        Observable<List<JobCategoryAttrTreeVo>> listJobCategoryAttrTree(Integer categoryId);
    }


    /**
     * 测试接口
     */
    public interface IJobService {
        /**
         * 查询招聘数据列表JobInfoList
         */
        @NetMethod(url = "/api/front/job/list", paramType = JSON_OBJECT, cacheMode = CacheMode.NO_CACHE, accessToken = true)
        Observable<JobInfoPage> jobInfList(JobInfoSearchRequest jobInfoSearchRequest);

        @NetMethod(url = "/api/front/job/list2User", paramType = JSON_OBJECT, cacheMode = CacheMode.NO_CACHE, accessToken = true)
        Observable<JobInfoPage> jobInfList2User(JobInfoSearchRequest jobInfoSearchRequest);

        /**
         * 测试JsonObject数组
         */
        @NetMethod(url = "/api/front/job/getJobInfo", parameterNames = {"jobId"}, action = GET,  cacheMode = CacheMode.NO_CACHE, accessToken = false)
        Observable<JobInfoVo> getJobInfo(String jobId);

        /**
         * 获取招工职位详情
         */
        @NetMethod(url = "/api/front/job/getJobInfoById", parameterNames = {"id"}, action = GET,  cacheMode = CacheMode.NO_CACHE, accessToken = false)
        Observable<JobInfoVo> getJobInfoById(Long id);

        /**
         * 获取用户招工职位详情
         */
        @NetMethod(url = "/api/front/job/getUserJobInfoById", parameterNames = {"id"}, action = GET,  cacheMode = CacheMode.NO_CACHE, accessToken = true)
        Observable<JobInfoVo> getUserJobInfoById(Long id);

        /**
         * 管理职位--关闭招工职位
         * @param jobInfoId
         * @return
         */
        @NetMethod(url = "/api/front/job/closeJob", parameterNames = {"jobInfoId"}, action = GET,  cacheMode = CacheMode.NO_CACHE, accessToken = true)
        Observable<Void> closeJobInfo(Long jobInfoId);


        /**
         * 测试范型返回
         */
       /* @NetMethod(url = "/book/findBooksByQueryParam", paramType = JSON_OBJECT, accessToken = false)
        Observable<QueryResult<Book>> findBooksByQueryParam(PageQuery pageQuery);*/

        /**
         * 客户端招聘职位发布 保存职位信息
         */
        @NetMethod(url = "/api/front/job/createJob", paramType = JSON_OBJECT, cacheMode = CacheMode.NO_CACHE, accessToken = true)
        Observable<Void> createJob(JobInfoRequest jobInfoRequest);
        /**
         * 客户端招聘职位发布 保存职位信息
         */
        @NetMethod(url = "/api/front/job/updateJob", paramType = JSON_OBJECT, cacheMode = CacheMode.NO_CACHE, accessToken = true)
        Observable<Void> updateJob(JobInfoRequest jobInfoRequest);
    }

    /**
     * 使用的是retrofit的接口定义
     */
    public interface IResumeService {

        @NetMethod(url = "/api/front/resume/list", paramType = JSON_OBJECT, cacheMode = CacheMode.NO_CACHE, accessToken = true)
        Observable<ResumeInfoPage> getResumeInfoList(ResumeInfoSearchRequest resumeInfoSearchRequest);
        /**
         * 获取个人简历数据列表
         * @return
         */
        @NetMethod(url = "/api/front/resume/getUserResumeInfo",action = GET, cacheMode = CacheMode.NO_CACHE, accessToken = true)
        Observable<ResumeInfoVo> getUserResumeInfo();

        /**
         * 获取指定用户简历数据
         * @return
         */
        @NetMethod(url = "/api/front/resume/getByUid",parameterNames = {"uid"}, action = GET, cacheMode = CacheMode.NO_CACHE, accessToken = true)
        Observable<ResumeInfoVo> getResumeInfoByUid(Long uid);

        /**
         * 获取指定用户简历数据
         * @return
         */
        @NetMethod(url = "/api/front/resume/getByResumeInfoId",parameterNames = {"resumeInfoId"}, action = GET, cacheMode = CacheMode.NO_CACHE, accessToken = true)
        Observable<ResumeInfoVo> getByResumeInfoId(Long resumeInfoId);

        /**
         * 更新个人简历数据
         * @param resumeInfoRequest
         * @return
         */
        @NetMethod(url = "/api/front/resume/updateUserResume", paramType = JSON_OBJECT, cacheMode = CacheMode.NO_CACHE, accessToken = true)
        Observable<Object> updateUserResume(@Body ResumeInfoRequest resumeInfoRequest);


        /**
         * 跟新工种薪资要求设置
         * @param resumeJobCategoryRequest
         * @return
         */
        @NetMethod(url = "/api/front/resume/updateUserResumeJobCategorySalary", paramType = JSON_OBJECT, cacheMode = CacheMode.NO_CACHE, accessToken = true)
        Observable<Object> updateUserResumeJobCategorySalary(@Body ResumeJobCategoryRequest resumeJobCategoryRequest);

        /**
         * 更新工种属性->职业亮点配置
         * @param resumeJobCategoryAttrResultRequest
         * @return
         */
        @NetMethod(url = "/api/front/resume/updateUserResumeJobCategoryAttrValue", paramType = JSON_OBJECT, cacheMode = CacheMode.NO_CACHE, accessToken = true)
        Observable<Object> updateUserResumeJobCategoryAttrValue(@Body ResumeJobCategoryAttrResultRequest resumeJobCategoryAttrResultRequest);

        /**
         * 获取简历过滤条件
         * @return
         */
        @NetMethod(url = "/api/front/resume/getResumeFilterConditionList", action = GET, cacheMode = CacheMode.NO_CACHE, accessToken = true)
        Observable<List<FilterConditionVo>> getResumeFilterConditionList();

    }

    /**
     *  系统配置接口
     */

    public interface IConfigService {
        /**
         * 获取菜单列表
         * @param type
         * @param target
         * @return
         */
        @NetMethod(url = "/api/front/config/menu/list",parameterNames = {"type","target"}, action = GET, cacheMode = CacheMode.NO_CACHE, accessToken = false)
        Observable<List<CategoryMenuVo>> getList(Integer type, Integer target);

        /**
         * 加测升级
         * @return
         */
        @NetMethod(url = "/api/front/update/checkUpdate", action = GET, cacheMode = CacheMode.NO_CACHE, accessToken = false)
        Observable<UpdateInfoVo> checkUpdate();

    }
    public interface IArticleService {
        /**
         * 获取菜单列表
         * @param cid
         * @param page
         * @return
         */
        @NetMethod(url = "/api/front/article/list/cid",parameterNames = {"cid","page"}, action = GET, cacheMode = CacheMode.NO_CACHE, accessToken = false)
        Observable<ArticlePage> getArticleList(Integer cid,Integer page);

        /**
         * 文章详情
         * @return
         */
        @NetMethod(url = "/api/front/article/info", parameterNames = {"id"},action = GET, cacheMode = CacheMode.NO_CACHE, accessToken = false)
        Observable<ArticleVo> getArticleInfo(Long id);

    }

    public interface IOther {
        /**
         * 获取tree结构的列表
         *
         */
        @NetMethod(url = "/api/front/city/list", action = GET, accessToken = true)
        Observable<List<SystemCityTreeVo>> listCityTree();
        /**
         * 收藏
         *
         * @param itemId 收藏对象iD
         * @param type 收藏对象类型 0=职位 1=简历
         * 未收藏-加入收藏
         * 已收藏-删除收藏
         */
        @NetMethod(parameterNames = {"itemId", "type"}, url = "/api/front/collection/collect",  paramType = FORM_BODY, accessToken = true)
        Observable<String> collect(Long itemId, int type);

        /**
         * 收藏列表
         * @param type  类型  0=职位 1=简历
         * @param page  页号
         * @return
         */
        @NetMethod(url = "/api/front/collection/list",parameterNames = {"type", "page"}, paramType = FORM_BODY , cacheMode = CacheMode.NO_CACHE, accessToken = true)
        Observable<CollectionPage> getCollectionList(Integer type, Integer page);

        /**
         * 获取所有具体工种列表
         */
        @NetMethod(url = "/api/front/jobCategory/leafList",action = GET, cacheMode = CacheMode.DEFAULT, accessToken = true)
        Observable<List<JobCategoryVo>> getJobCategoryLeafList();

        /**
         * 获取用户职位订阅详情
         * @return JobBookingVo
         */
        @NetMethod(url = "/api/front/jobBooking/getBookInfo",action = GET, cacheMode = CacheMode.NO_CACHE, accessToken = true)
        Observable<JobBookingVo> getJobBookingInfo();

        /**
         * 获取所有具体工种列表
         */
        @NetMethod(url = "/api/front/jobBooking/booking",action = PUT, paramType = JSON_OBJECT, cacheMode = CacheMode.DEFAULT, accessToken = true)
        Observable<Object> addJobBooking(JobBookingBo bo);
    }

}
